import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../components/Login.vue';
const Login = () =>
    import ( /* webpackChunkName:"login_home_welcome" */ '../components/Login.vue')
    // import Home from '../components/Home.vue'
const Home = () =>
    import ( /* webpackChunkName:"login_home_welcome" */ '../components/Home.vue')
    // import Welcome from '../components/Welcome.vue';
const Welcome = () =>
    import ( /* webpackChunkName:"login_home_welcome" */ '../components/Welcome.vue')

const Users = () =>
    import ( /* webpackChunkName:"users" */ '../components/Users.vue')

// import Users from '../components/Users.vue';
const Rights = () =>
    import ( /* webpackChunkName:"rights_roles" */ '../components/Rights.vue')

// import Rights from '../components/Rights.vue';
const Roles = () =>
    import ( /* webpackChunkName:"rights_roles" */ '../components/Roles.vue')

// import Roles from '../components/Roles.vue';
const Report = () =>
    import ( /* webpackChunkName:"rights_roles" */ '../components/Report.vue')

// import Report from '../components/Report.vue'
Vue.use(VueRouter)

const routes = [

    { path: '/login', component: Login },
    {
        path: '/home',
        component: Home,
        redirect: '/welcome',
        children: [
            { path: '/', component: Welcome },
            { path: "/users", component: Users },
            { path: '/rights', component: Rights },
            { path: '/roles', component: Roles },
            { path: '/reports', component: Report }
        ]
    },

]

const router = new VueRouter({
    routes
})
router.beforeEach((to, from, next) => {
    let tokenStr = sessionStorage.getItem('token')
    switch (to.path) {
        case '/login':
            next();
            return;
        default:
            if (tokenStr) {
                next()
            } else {
                next('/login')
            }
    }
})
export default router